package com.ruoyi.web.controller.yijing;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yijing.domain.YjBookChapter;
import com.ruoyi.yijing.service.IYjBookChapterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 书本章节Controller
 * 
 * @author ruoyi
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/yijing/chapter")
public class YjBookChapterController extends BaseController
{
    @Autowired
    private IYjBookChapterService yjBookChapterService;

    /**
     * 查询书本章节列表
     */
    ////@PreAuthorize("@ss.hasPermi('yijing:chapter:list')")
    @GetMapping("/list")
    public TableDataInfo list(YjBookChapter yjBookChapter)
    {
        if (yjBookChapter.getBookId() == null){
            yjBookChapter.setBookId(0L);
        }
        startPage();
        List<YjBookChapter> list = yjBookChapterService.selectYjBookChapterList(yjBookChapter);
        return getDataTable(list);
    }

    /**
     * 获取书本章节详细信息
     */
    ////@PreAuthorize("@ss.hasPermi('yijing:chapter:query')")
    @GetMapping(value = "/{chapterId}")
    public AjaxResult getInfo(@PathVariable("chapterId") Long chapterId)
    {
        return success(yjBookChapterService.selectYjBookChapterByChapterId(chapterId));
    }

    /**
     * 新增书本章节
     */
    ////@PreAuthorize("@ss.hasPermi('yijing:chapter:add')")
    @Log(title = "书本章节", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YjBookChapter yjBookChapter)
    {
        return toAjax(yjBookChapterService.insertYjBookChapter(yjBookChapter));
    }

    /**
     * 修改书本章节
     */
    ////@PreAuthorize("@ss.hasPermi('yijing:chapter:edit')")
    @Log(title = "书本章节", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YjBookChapter yjBookChapter)
    {
        return toAjax(yjBookChapterService.updateYjBookChapter(yjBookChapter));
    }

    /**
     * 删除书本章节
     */
    ////@PreAuthorize("@ss.hasPermi('yijing:chapter:remove')")
    @Log(title = "书本章节", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chapterId}")
    public AjaxResult remove(@PathVariable Long chapterId)
    {
        return toAjax(yjBookChapterService.deleteYjBookChapterByChapterId(chapterId));
    }
}
